#ifndef __KEYBOARD_H__
#define __KEYBOARD_H__

#include "CONFIG.H"

#define ROW1	P34
#define ROW2	P35
#define ROW3	P40
#define ROW4	P41

#define COL1	P03
#define COL2	P06
#define COL3	P07
#define COL4	P17

#define DOWN	0
#define UP  	1

#define ROW_NUM  	4
#define COL_NUM  	4

#define IF_KEY_UP(row,col)    ((last_states & (1L << (row * COL_NUM + col))) > 0)
#define IF_KEY_DOWN(row,col)  ((last_states & (1L << (row * COL_NUM + col))) == 0)
#define IS_KEY_DOWN(row,col)	  last_states &= ~(1L << (row * COL_NUM + col))
#define IS_KEY_UP(row,col)   	  last_states |=  (1L << (row * COL_NUM + col))
#define KEY_START(row,col)	  (((last_states & (1L << (row * COL_NUM + col))) == 0) ? 0 : 1)

extern void USER_CALL_DOWN(u8 row,u8 col);

extern void USER_CALL_UP(u8 row,u8 col);

void KEYBOARD_init(void);

void KEYBOARD_scan(void);

#endif